import {defineStore} from "pinia";
import {computed, ref} from "vue";

export const useTokenStore = defineStore("token", () => {
    const token = ref(null);
    //返回token
    const tokenStr = computed(() => {
        return token.value;
    });
    //更新token
    function updateToken(tk) {
        token.value = tk;
    }
    //重置token
    function $reset() {
        token.value = null;
    }

    return {token, tokenStr, updateToken, $reset};
},{
    persist:{
        key:'token',
        storage:sessionStorage,
    }
});